package com.zz.ecommerce.declareManage.exportB2BDeclare.exchangeSettlementManager;

import com.zz.ecommerce.common.CommonDao;
import com.zz.ecommerce.common.GridRequest;
import com.zz.ecommerce.common.GridResult;
import com.zz.ecommerce.declareManage.exportB2BDeclare.exchangeSettlementManager.bean.TExchangeSettlement;
import com.zz.ecommerce.declareManage.exportB2BDeclare.exchangeSettlementManager.service.TExchangeSettlementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/exchangeSettlement")
public class TExchangeSettlementController {
    @Autowired
    CommonDao commonDao;
    @Autowired
    TExchangeSettlementService exchangeSettlementService;

    /**
     * 结汇管理列表页
     *
     * @return
     */
    @RequestMapping(value = "TExchangeSettlementManager", method = RequestMethod.GET)
    public String TExchangeSettlementManager() {
        return "declareManage/exchangeSettlement/texchangesettlement_manager";
    }

    /**
     * 查询结汇列表信息
     *
     * @param gridRequest
     * @param tExchangeSettlement
     * @return
     */
    @RequestMapping(value = "qryTExchangeSettlementPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public GridResult<TExchangeSettlement> qryTExchangeSettlementPage(GridRequest gridRequest, TExchangeSettlement tExchangeSettlement) {
        List<TExchangeSettlement> list = commonDao.pageWhere("T_EXCHANGE_SETTLEMENT", tExchangeSettlement, gridRequest.getStart(), gridRequest.getEnd(), "", "");
        long count = commonDao.countWhere("T_EXCHANGE_SETTLEMENT", tExchangeSettlement, "");
        return new GridResult<TExchangeSettlement>(list, gridRequest, count);
    }

    /**
     * 保存结汇信息
     *
     * @param tExchangeSettlement
     * @return
     */
    @RequestMapping(value = "saveTExchangeSettlement", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String saveTExchangeSettlement(TExchangeSettlement tExchangeSettlement) {
        try {
            return exchangeSettlementService.saveExchangeSettlement(tExchangeSettlement);
        } catch (Exception e) {
            return "保存失败:" + e.getMessage();
        }
    }

    /**
     * 删除结汇信息
     *
     * @param indxs
     * @return
     */
    @RequestMapping(value = "deleteExchangeSettlement", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String deleteExchangeSettlement(String indxs) {
        try {
            return exchangeSettlementService.deleteExchangeSettlement(indxs);
        } catch (Exception e) {
            return "保存失败:" + e.getMessage();
        }
    }

    /**
     * 申报结汇信息
     *
     * @param indxs
     * @return
     */
    @RequestMapping(value = "decExchangeSettlement", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String decExchangeSettlement(String indxs) {
        try {
            return exchangeSettlementService.decExchangeSettlement(indxs);
        } catch (Exception e) {
            return "保存失败:" + e.getMessage();
        }
    }

    /**
     * 查询结汇信息
     *
     * @param tExchangeSettlement
     * @param modelMap
     * @return
     */
    @RequestMapping(value = "getTExchangeSettlementDetail", method = {RequestMethod.GET, RequestMethod.POST})
    public String getTExchangeSettlementDetail(TExchangeSettlement tExchangeSettlement,String modify, ModelMap modelMap) {
        TExchangeSettlement tExchangeSettlementDetail = (TExchangeSettlement) commonDao.qryOneCommon("T_EXCHANGE_SETTLEMENT", tExchangeSettlement, "");
        modelMap.put("tExchangeSettlement", tExchangeSettlementDetail);
        modelMap.put("modify","false".equals(modify));
        return "declareManage/exchangeSettlement/texchangesettlement_detail";
    }
}
